#include <iostream>

using namespace std;
const int N = 10;

int n;
bool row[N], col[N], dg[N* 2], udg[N*2];
char g[N][N];
int a[N][N];


void dfs(int x, int y, int s, int p){
    if(s > n  && p > n) return;
    
    if(y == n) y = 0, x++;
    if(x == n) {
        if(s == n){
            for(int i = 0;i < n; i ++) puts(g[i]);
            puts("");
        }
        return;
    }
    g[x][y] = '.';
    dfs(x,y+1, s, p);
    if(!row[x] && !col[y] && !dg[x +y] && !udg[x - y + n])
    {
        row[x] = col[y] = dg[x + y] = udg[ x - y + n] = true;
        g[x][y] = 'Q';
        dfs(x, y+1, s+1);
        g[x][y] = '.';
        row[x] = col[y] = dg[x + y] = udg[ x - y + n] = false;

    }
}

int main(){
    cin >> n;
    for(int i =0; i < n; i ++)
        for(int j = 0; j < n; j ++)
            cin >> a[i][j];
            
    dfs(0, 0, 0, 0);
    return 0;
}
